<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box{
            position: relative;
            width: 400px;
            border-bottom: 1px solid #ccc;
            margin: 100px auto;
        }
        .box input{
            width: 370px;
            height: 30px;
            border: 0;
            outline: none;
        }
        .box label{
            position: absolute;
            top: -5px;
            right: 30px;
            /* width: 24px; */

        }
    </style>
</head>
<body>
    <div class="box">
        <label for="">
            <button>按钮</button>
        </label>
        <input type="password" name="" id="">
    </div>

    <script>
        var input=document.querySelector('input');
        var btn=document.querySelector('button');
        var flag=1
        btn.onclick=function(){
            flag=1-flag;
            if(flag==0){
                input.type='text';
            }
            else{
                input.type='password';
            }
        }
    </script>
</body>
</html>